package com.zy.qudadid.presenter;

import com.zy.qudadid.model.Res;
import com.zy.qudadid.model.Stroke;
import com.zy.qudadid.model.StrokeInfor;
import com.zy.qudadid.model.StrokeInfors;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.RefreshAndLoadMorePresenter;
import com.zy.qudadid.ui.activity.StrokeAllActivity;
import com.zy.qudadid.ui.view.StrokeAllView;
import com.zy.qudadid.utils.AESCrypt;
import com.zy.qudadid.utils.StringUtil;
import com.zy.qudadid.utils.UserUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ASUS on 2017/2/17.
 */

public class StrokeAllPresenter extends RefreshAndLoadMorePresenter<StrokeAllView>{

    //查询已完成订单列表
    @Override
    public void getData(int page, final int count) {
        Map mapTravel = new HashMap();
        mapTravel.put("user_id", new UserUtil(view.getContext()).getUserId());
        mapTravel.put("type", "1");
        mapTravel.put("car_type", view.getType());
        mapTravel.put("finished", view.getfinished());
        mapTravel.put("nowpage", page);
        mapTravel.put("page_num", count);
        String jsonTravel = StringUtil.toJson(mapTravel);
        String d="";
        try {
            d = AESCrypt.getInstance().encrypt(jsonTravel);
            d = StringUtil.replaceBlank(d);
        } catch (Exception ex) {
        }

        Subscription subscription1 = Net.getService()
                .MyStroke(d)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<StrokeInfors>>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Res<StrokeInfors> res) {
                        if (res.code == Const.OK) {
                            view.successUnfinished(res.datas.infor);
                            setDataStatus(res.datas.infor);
                        } else {
                            view.error();
                        }
                    }
                });

        addSubscription(subscription1);


    }

    //查询未完成订单列表
    public void getDataForUnfinished(final int page, final int count) {
//        Map mapTravel = new HashMap();
//        mapTravel.put("user_id", new UserUtil(view.getContext()).getUserId());
//       // mapTravel.put("user_id", 158);
//        mapTravel.put("type", "1");
//        mapTravel.put("car_type", "1");
//        mapTravel.put("finished", "1");
//        mapTravel.put("nowpage", 1);
//        mapTravel.put("page_num", 10);
//        String d = "";
//        String jsonTravel = StringUtil.toJson(mapTravel);
//        try {
//            d = AESCrypt.getInstance().encrypt(jsonTravel);
//            //String d1 = d;
//        } catch (Exception ex) {
//        }


    }
}
